#!/bin/bash

# Copyright © 2021 sev, p
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

h="$1"
l="$2"

if [ -z "$h" ]; then echo "usage: fedi-tl hostname [true|false]" >&2; exit 1; fi
if [ -z "$l" ]; then l=true; fi

# TODO:  Use the non pleroma-specific one, pipe through
# htmlfmt or something.  Pleroma's "text/plain" screws up
# line breaks.

curl -k -vv -4 https://$h/api/v1/timelines/public?local=$l | \
	tee /tmp/fedi-tl-$h | \
	jq  -r 'map(.account.acct + " [" + .created_at + "]", "\t" + .pleroma.content["text/plain"], "\n")|join("\n")'
